home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gtlayout / source / ltp_correctitemlist.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  2KB  |  101 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #include "gtlayout_global.h"
  11.  
  12. #include "Assert.h"
  13.  
  14. #ifdef DO_MENUS    /* Support code */
  15.  
  16.     /* LTP_CorrectItemList(RootMenu *Root,ItemNode *First,ItemNode *Last):
  17.      *
  18.      *    Chop nasty menus in two if they're too tall for this screen.
  19.      */
  20.  
  21. BOOL
  22. LTP_CorrectItemList(RootMenu *Root,ItemNode *First,ItemNode *Last)
  23. {
  24.     ItemNode    *Item;
  25.     ULONG         Count = 0;
  26.     LONG         Mask;
  27.     BOOL         Overshoot = FALSE;
  28.  
  29.     Mask = First->Flags & ITEMF_IsSub;
  30.  
  31.         // Count the number of items in this menu
  32.         // and check if there is one too many in it
  33.  
  34.     for(Item = First ; Item->Node.mln_Succ ; Item = (ItemNode *)Item->Node.mln_Succ)
  35.     {
  36.         if((Item->Flags & ITEMF_IsSub) == Mask)
  37.         {
  38.             Count++;
  39.  
  40.             if(Item->Top + Item->Item.Height + 2 > Root->Screen->Height)
  41.                 Overshoot = TRUE;
  42.         }
  43.  
  44.         if(Item == Last)
  45.             break;
  46.     }
  47.  
  48.         // Did we scrape it?
  49.  
  50.     if(Overshoot && Count > 1)
  51.     {
  52.         ItemNode    *Here;
  53.         ULONG         i = (Count + 1) / 2;
  54.         LONG         Top,Left;
  55.  
  56.             // Find the median or whatever it's called in this part of the world
  57.  
  58.         for(Here = First ; i > 0 && Here->Node.mln_Succ ; Here = (ItemNode *)Here->Node.mln_Succ)
  59.         {
  60.             if((Here->Flags & ITEMF_IsSub) == Mask)
  61.                 i--;
  62.         }
  63.  
  64.             // Shrink the two halves of the menu down to
  65.             // their minimum sizes
  66.  
  67.         LTP_ShrinkMenu(Root,First,(ItemNode *)Here->Node.mln_Pred,Mask);
  68.         LTP_ShrinkMenu(Root,Here,Last,Mask);
  69.  
  70.             // Chop off the other half and stick it
  71.             // on at the right
  72.  
  73.         Left    = First->Item.LeftEdge + First->Item.Width + 2;
  74.         Top        = First->Item.TopEdge;
  75.  
  76.             // Move the items over to the right
  77.  
  78.         for(;;)
  79.         {
  80.             if((Here->Flags & ITEMF_IsSub) == Mask)
  81.             {
  82.                 Here->Item.LeftEdge    = Left;
  83.                 Here->Item.TopEdge    = Top;
  84.  
  85.                 Top += Here->Item.Height;
  86.             }
  87.  
  88.             if(Here == Last)
  89.                 break;
  90.             else
  91.                 Here = (ItemNode *)Here->Node.mln_Succ;
  92.         }
  93.  
  94.         return(TRUE);
  95.     }
  96.     else
  97.         return(FALSE);
  98. }
  99.  
  100. #endif    /* DO_MENUS */
  101.